import React, { Component } from 'react';
import { Layout, Button,Menu } from 'antd';
import {
    PieChartOutlined,
  } from '@ant-design/icons';
import {getResource} from '../../api/user';
import {NavLink,Switch,Route, Redirect} from 'react-router-dom';
import Home from './home';
import MeetManger from './meetManger';
import MyOrder from './myOrder';
import OrderApproval from './orderApproval';
import OrderApproval2 from './orderApproval2';
import OrderMeet from './orderMeet';
import OrderRoom from './orderRoom';
import Set from './set'; 

const { Header, Sider, Content } = Layout;


export default class Main extends Component {
    state = {
        asideList:[]
    }
    componentDidMount(){

        console.log(this.props)
        //获取侧边菜单
        getResource().then(res => {
            if(res.data.code === 1){
                this.setState({
                    asideList:res.data.data
                })
            }
        })
    }
    render() {
        let {asideList} = this.state;
        return (
            <Layout>
                <Header>
                    {localStorage.getItem('username')}--{localStorage.getItem('role_name')}
                    <Button>退出</Button>
                </Header>
                <Layout>
                    <Sider>
                        <Menu
                            defaultSelectedKeys={[this.props.location.pathname]}
                            mode="inline"
                            theme="dark"
                            >
                            {asideList.map(item => <Menu.Item key={item.resource_router} icon={<PieChartOutlined />}>
                                <NavLink to={item.resource_router}>{item.resource_name}</NavLink>
                            </Menu.Item>)}
                        </Menu>
                    </Sider>
                    <Content>
                        <Switch>
                            <Route path='/main/home' component={Home}/>
                            <Route path='/main/orderRoom' component={OrderRoom}/>
                            <Route path='/main/myOrder' component={MyOrder}/>
                            <Route path='/main/orderApproval' component={OrderApproval}/>
                            <Route path='/main/orderApproval2' component={OrderApproval2}/>
                            <Route path='/main/set' component={Set}/>
                            <Route path='/main/orderMeet' component={OrderMeet}/>
                            <Route path='/main/meetManger' component={MeetManger}/>
                            <Redirect from="/" to="/main/home"></Redirect>
                        </Switch>       
                    </Content>
                </Layout>
            </Layout>
        )
    }
}
